package com.cakemallproject.service.impl;

import com.cakemallproject.mapper.UsersMapper;
import com.cakemallproject.pojo.mapperObj.User;
import com.cakemallproject.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UsersServiceImpl implements UsersService {
    @Autowired
    private UsersMapper usersMapper;

    @Override
    public List<User> list() {
        List<User> list = usersMapper.list();
        for (User user : list) {
            if (user.getUid() == 1 && user.getStatus() == 999) {
                list.remove(user);
                break;
            }
        }
        return list;
    }

    @Override
    public void insert(User user) {
        usersMapper.insert(user);
    }

    @Override
    public User login(User user) {
        return usersMapper.getByUsernameOrEmailAndPassword(user);
    }

    @Override
    public User loginByUid(Integer uid) {
        return usersMapper.getByUid(uid);
    }

    @Override
    public User getByUsername(String username) {
        return usersMapper.getByUsername(username);
    }

    @Override
    public void delete(List<Integer> ids) {
        usersMapper.delete(ids);
    }

    @Override
    public void update(User user) {
        usersMapper.update(user);
    }
}
